package util;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class DBUtil {
  
  private static String DRIVER = "com.mysql.jdbc.Driver";
  private static String URL = "jdbc:mysql://localhost:3306/dianchang";
  private static String USERNAME = "root";
  private static String PASSWORD = "12358";
  private static Connection conn;
  Statement stmt;
  ResultSet rs;
  
  /*public static void initParam(String paramFlie) throws Exception{
	  Properties props=new Properties();
	  String fullFileName=DBUtil.class.getResource(paramFlie).getFile();
	  props.load(new FileInputStream(fullFileName));
	  DRIVER=props.getProperty("DRIVER");
	  URL=props.getProperty("URL");
	  USERNAME=props.getProperty("USERNAME");
	  PASSWORD=props.getProperty("PASSWORD");
  }*/
  public static Connection getConnection(){
	  try{
		  //initParam("mysql.ini");
		  Class.forName(DRIVER);
		  conn=DriverManager.getConnection(URL,USERNAME,PASSWORD);
		  } catch (ClassNotFoundException e){
			  e.printStackTrace();
		  } catch(SQLException e){
			  e.printStackTrace();
		  }catch(Exception e){
			  e.printStackTrace();
		  }
	  return conn;
  }
  public void closeConn(Connection conn){
	  if(conn !=null){
		  try{
			  conn.close();
		  }catch(SQLException e){
			  e.printStackTrace();
		  }
	  }
  }
}
